<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="bootstrap-3.0.3/css/bootstrap.min.css">
<script type="text/javascript" src="bootstrap-3.0.3/js/bootstrap.js"></script>
<script type="text/javascript" src="script/jquery-1.4.1.js"></script>
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=C2b42eb4a9ea4cd555d0fc891caf9095"></script>
</head>
<body>
	<div class="container">
		<%@ include file="shared/front_header.jsp"%>

		<div class="row">
			<div class="col-md-9 col-md-push-3">
				<div class="row">
					<div class="hero-unit">
						<h1>${house.photo.title }</h1>
						<p>
							<img src="CoverImages/${house.photo.fileName }" alt="...">
						</p>
						<p>${house.topic}</p>
						<p>${house.content }</p>
					</div>
					<a href="message?fid=${user.id }&tid=${house.user.id}">留言房东</a>
					<a href="index">返回首页</a>
				</div>
				<div class="panel-body">
					<div id="allmap" style="width: 100%; height: 400px;"></div>
				</div>
				
			</div>
			<%@ include file="shared/nav.jsp"%>
		</div>
	</div>
	
	<script type="text/javascript">
	// 百度地图API功能
	var longitude=${house.longitude}
	var latitude=${house.latitude}
	
	var map = new BMap.Map("allmap");
	map.centerAndZoom(new BMap.Point(116.404, 39.915), 15);

	map.enableScrollWheelZoom(true);
	map.disableDragging();     //禁止拖拽
	setTimeout(function(){
	   map.enableDragging();   //两秒后开启拖拽
	   //map.enableInertialDragging();   //两秒后开启惯性拖拽
	}, 2000);
	
	var myP1;
	var geolocation = new BMap.Geolocation();
	geolocation.getCurrentPosition(function(r){
		if(this.getStatus() == BMAP_STATUS_SUCCESS){
			var mk = new BMap.Marker(r.point);
			map.addOverlay(mk);
			map.panTo(r.point);
			myP1 = new BMap.Point(r.point.lng,r.point.lat);    //起点
			
			var myP2 = new BMap.Point(longitude,latitude);    //终点
			var myIcon = new BMap.Icon("http://lbsyun.baidu.com/jsdemo/img/Mario.png", new BMap.Size(32, 70), {    //小车图片
				//offset: new BMap.Size(0, -5),    //相当于CSS精灵
				imageOffset: new BMap.Size(0, 0)    //图片的偏移量。为了是图片底部中心对准坐标点。
			  });
			var driving2 = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}});    //驾车实例
			driving2.search(myP1, myP2);    //显示一条公交线路
			
		}
		else {
			alert('failed'+this.getStatus());
		}        
	},{enableHighAccuracy: true})
	
	
	

	window.run = function (){
		var driving = new BMap.DrivingRoute(map);    //驾车实例
		driving.search(myP1, myP2);
		driving.setSearchCompleteCallback(function(){
			var pts = driving.getResults().getPlan(0).getRoute(0).getPath();    //通过驾车实例，获得一系列点的数组
			var paths = pts.length;    //获得有几个点

			var carMk = new BMap.Marker(pts[0],{icon:myIcon});
			map.addOverlay(carMk);
			i=0;
			function resetMkPoint(i){
				carMk.setPosition(pts[i]);
				if(i < paths){
					setTimeout(function(){
						i++;
						resetMkPoint(i);
					},100);
				}
			}
			setTimeout(function(){
				resetMkPoint(5);
			},100)

		});
	}

	setTimeout(function(){
		run();
	},1500);
</script>
</body>
</html>